#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define STDIN
//#define DEBUG

int n;
int sticks[100];
int used[100];

#ifdef DEBUG
void print_a()
{
	int i;
	for (i = 0; i < n; ++i)
	{
		printf("%d ", sticks[i]);
	}
	printf("\n");
	for (i = 0; i < n; ++i)
	{
		printf("%d ", used[i]);
	}
	printf("\n");
}
#endif

int search(int num, int begin, int x, int left)//拼凑num根木棒的x长度的剩余长度
{
#ifdef DEBUG
	printf("num: %d begin: %d x: %d left: %d\n", num, begin, x, left);
	print_a();
#endif
	int i;

	if (begin > n)
		return 0;

	if (num == 0 && left == 0)
	{
		return 1;
	}
	else if (num == 0 && left != 0)
		return 0;
	else if (num != 0 && left == 0)//一截木木棒拼凑完成
	{
		if (num-1 == 0)//已拼完所需要的木棒，检查是否用完所有的长度
		{
#ifdef DEBUG
			printf("成功\n");
#endif
			return 1;
		}
		return search(num-1, 0, x, x);//继续拼凑下一根
	}

	int pre = sticks[begin]+1;//因为sticks递减排列

	for (i = begin; i < n; ++i)
	{
		if (used[i] == 1)
			continue;
		if (left - sticks[i] < 0)
			continue;

		if (sticks[i] == pre)//此次测试的值与前一次相同，跳过
			continue;
		used[i] = 1;
		if (search(num, i+1, x, left - sticks[i]) == 1)
		{
#ifdef DEBUG
			printf("search(%d, %d, %d, %d)返回: %d\n", num, i+1, x, left-sticks[i], 1);
#endif
			return 1;
		}
		used[i] = 0;
		pre = sticks[i];
		if (sticks[i] == left || left == x)
			break;
	}
	return 0;
}


int less ( const void *a , const void *b )
{
	return -(*(int *)a - *(int *)b);
}


void process()
{
	int i;

	//先排个序
	//
	qsort(sticks, n, sizeof(sticks[0]), less);

#ifdef DEBUG
	print_a();
#endif

	int sum = 0, len = 0;
	for (i = 0; i < n; ++i)
		sum += sticks[i];
	for (len = sticks[0]; len <= sum; ++len)
	{
#ifdef DEBUG
		printf("len: %d:\n", len);
#endif
		memset(used, 0, sizeof(used));
		if (sum % len != 0)
			continue;
		if  (search(sum / len, 0, len, len) == 1)
		{
			printf("%d\n", len);
			break;
		}
	}
}

int main()
{
#ifdef STDIN
	freopen("bin/1011.in", "r", stdin);
#endif

	while(1)
	{
		scanf("%d", &n);
		if (n == 0)
			break;

		int i;
		for (i = 0; i < n; ++i)
		{
			scanf("%d", &sticks[i]);
			used[i] = 0;
		}

		process();
	}

	return 0;
}
